package com.xiaolong.server;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.xiaolong.mapper.UserMapper;
import com.xiaolong.model.User;

@Service
@Transactional
public class UserServiceImpl implements IUserService {
	
	@Resource
	private UserMapper userMapper;
	
	@Override
	@Cacheable(value="andCache")
	public User get(long id) {
		System.out.println("get form DB!");
		return userMapper.get(id);
	}

	@Override
	@Transactional(isolation=Isolation.READ_COMMITTED,propagation=Propagation.REQUIRED)
	public long save(User u) {
		// TODO Auto-generated method stub
		return userMapper.save(u);
	}

	@Override
	public long update(User u) {
		// TODO Auto-generated method stub
		return userMapper.update(u);
	}

	@Override
	@CacheEvict(value="andCache")
	public long delete(long id) {
		// TODO Auto-generated method stub
		return userMapper.delete(id);
	}

	@Override
	public List<User> find(Map<String, Object> Map) {
		// TODO Auto-generated method stub
		return userMapper.find(Map);
	}

	@Override
	public User getByName(String userName) {
		// TODO Auto-generated method stub
		return userMapper.getByName(userName);
	}

}
